﻿import com.audiopackage.GSound;

class com.audiopackage.GSequencer
{
	private var GSounds: Array;
	private var track: Array;
	
	private var ticksPer16: Number = 1920 * 2;
	private var timer: Number;
	
	function GSequencer()
	{
		timer = 0;
		GSounds = new Array();
	}
	
	function addChannelListener( gSound: GSound, channel: Number ): Void
	{
		GSounds[ channel ] = gSound;
	}
	
	function onSync( delay: Number ): Void
	{
		var events: Array = track[ timer ];
		
		var n = events.length;
		
		while( --n > -1 )
		{
			var event = events[n];
			
			var gSound = GSounds[ event.note ];
			gSound.setVolume( event.vel );
			gSound.start( delay , 1 );
		}
		timer += ticksPer16;
	}
	
	function setTrack( track: Array ): Void
	{
		this.track = track;
	}
}